package com.hefei.garden.service.impl;

import com.hefei.garden.WangHuCityApplication;
import com.hefei.garden.service.AsyncTestService;
import lombok.SneakyThrows;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author: devil
 * @Date: 2022/9/26 21
 * @Description: 异步+自定义线程池+注意事务+失效场景+原理
 */
@Service
public class AsyncTestServiceImpl implements AsyncTestService {

    private static final Logger LOGGER = LoggerFactory.getLogger(WangHuCityApplication.class);

    @SneakyThrows
    @Async(value = "myExecutor")
    @Override
    public void getContent() {
        TimeUnit.SECONDS.sleep(4);
        LOGGER.info("sleep 4秒，输出结果...");
    }

    /**
     * 失效。事务
     */
    @Override
    public void getContent2() {
        getContent();
    }

}
